<template>
	<view class="u-page">
		<userheader ref="userheader" page="admin" :post="{}" v-on:onGetUserinfo="onGetUserinfo"/>
		<view class="container">
			<view class="item" v-if="apply.length>0">
				<view class="title" style="color: red;">
					客户审核
				</view>
				<view class="info">
					<view v-for="(a,i) in apply" :key="i" class="line" @click="goShenhe(a.id)">
						<text v-if="a.info.customer_type=='company'">【企业】{{a.info.name}}</text>
						<text v-if="a.info.customer_type=='family'">【住户】{{a.info.address}}</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
				</view>
			</view>
			<view class="item">
				<view class="title">
					客户分布
				</view>
				<view class="info">
					<view class="line" @click="goKehu">
						服务客户：{{store.store_num}}家，本月新增：{{store.store_month_num}}家
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>		
				</view>
			</view>
			<view class="item">
				<view class="title">
					<text v-if="role=='admin'">服务商收益</text>
					<text v-if="role=='seller'">销售收益</text>
				</view>
				<view class="info">
					<view class="line" @click="goShouyi">
						累计收益：￥{{shouyi.all_money}}，今日收益：￥{{shouyi.today_money}}
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
				</view>
			</view>
			<view class="item" v-if="role=='admin'">
				<view class="title">
					销售经理
				</view>
				<view class="info">
					<view class="line" @click="goJingli">
						员工：{{jingli}}人</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>		
				</view>
			</view>
			<view class="item" v-if="role=='seller'">
				<view class="title">
					销售结算
				</view>
				<view class="info">
					<view class="line" @click="goJiesuan">
						结算账单{{jiesuan}}次
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>		
				</view>
			</view>
			<view class="item" v-if="coupon">
				<view class="title">
					客户卡券
				</view>
				<view class="info">
					<view class="line" @click="goCard('discount')" v-if="coupon.discount">
						<text>折扣券：{{coupon.discount.count}}张</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="line" @click="goCard('full_minus')" v-if="coupon.full_minus">
						<text>满减券：{{coupon.full_minus.count}}张</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="line" @click="goCard('cash')" v-if="coupon.cash">
						<text>代金券：{{coupon.cash.count}}张</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="line" @click="goCard('goods')" v-if="coupon.goods">
						<text>商品券：{{coupon.goods.count}}张，余额：{{coupon.goods.total}}次</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="line" @click="goCard('card')" v-if="coupon.card">
						<text>会员卡：{{coupon.card.count}}张，余额：￥{{coupon.card.balance}}</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="line" @click="goCard(0)" v-if="coupon.length!=undefined && coupon.length===0">
						<text>无</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>		
				</view>
			</view>
			<view class="item">
				<view class="title">
					月付账单
				</view>
				<view class="info">
					<view class="line" @click="goBill">
						{{bill}}条账单未结清
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>		
				</view>
			</view>
			<view class="item" v-if="role=='admin'">
				<view class="title">
					物流配送(送达/总数)
				</view>
				<view class="info">
					<view class="line" @click="goWuliu">
						<text>今日订单：{{wuliu.receive}}单/{{wuliu.total}}单</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>					
				</view>
			</view>
			<view class="item" v-if="role=='admin'">
				<view class="title">
					网格司机
				</view>
				<view class="info">
					<view class="line" @click="goGird">
						<text>{{gird}}个网格，{{driver}}名司机</text>
						<view class="rightbox">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
				</view>
			</view>
			<view class="item" v-if="qrcode">
				<view class="title">
					推广二维码
				</view>
				<view class="info">
					<view class="qrcode">
						<image :src="qrcode"></image>
						<u-button size="small" type="primary" text="保存图片" @click="saveImg()"></u-button>
					</view>
				</view>
			</view>
		</view>	
		<u-tabbar value="index">
			<u-tabbar-item text="客户" name="store" icon="home-fill" @click="goStore"></u-tabbar-item>
			<u-tabbar-item text="订单" name="order" icon="file-text-fill" @click="goOrder"></u-tabbar-item>
			<u-tabbar-item text="我的" name="index" icon="account-fill"></u-tabbar-item> 
		</u-tabbar>
	</view>
</template>

<script>
	import {baseUrl,methods} from '@/utils/methods.js';
	import userheader from '@/pages/components/userheader';
	export default {
		components: {
			userheader
		},
		data() {
			return {
				role:'',
				bill:0,
				apply:[],
				gird:'',
				driver:'',
				store:{
					store_num:0,
					store_month_num:0
				},
				wuliu:{
					total:0,
					receive:0
				},
				jingli:0,
				jiesuan:0,
				shouyi:{
					all_money:0,
					today_money:0
				},
				qrcode:'',
				coupon:''
			}
		},
		onLoad() {
			let token=uni.getStorageSync('token');
			this.qrcode=baseUrl+'api/admin/admin/qrcode?token='+token;
		}, 
		methods: {
			...methods,
			onGetUserinfo:function(e){
				this.role=e.role;
				this.gird=e.gird;
				this.driver=e.driver;
				this.apply=e.apply;
				this.store=e.store;
				this.jingli=e.jingli;
				this.jiesuan=e.jiesuan;
				this.shouyi=e.shouyi;
				this.wuliu=e.wuliu;
				this.coupon=e.coupon;
			},
			goBill:function(){
				this.$navigateTo('admin/monthbill');
			},
			goShouyi:function(){
				if(this.role=='admin'){
					this.$msg('开发中');
				}
				if(this.role=='seller'){
					this.$navigateTo('admin/shouyi');
				}
			},
			goWuliu:function(){
				this.$navigateTo('admin/wuliu');
			},
			goJiesuan:function(){
				this.$navigateTo('admin/jiesuan');
			},
			goJingli:function(){
				this.$navigateTo('admin/jingli');
			},
			goKehu:function(){
				this.$navigateTo('admin/map');
			},
			goCard:function(type){
				this.$navigateTo('admin/card?type='+type);
			},
			goShenhe:function(id){
				this.$navigateTo('admin/addstore?register_id='+id);
			},
			goGird:function(){
				this.$navigateTo('admin/gird');
			},
			goStore:function(){
				this.$redirectTo('admin/store');			
			},
			goOrder:function(){
				this.$redirectTo('admin/orderlist');	
			},
			saveImg:function(){
				let imgSrc=baseUrl+'api/admin/admin/qrcode?download=1&token='+uni.getStorageSync('token');
				let that=this;
				wx.getImageInfo({
				   src: imgSrc,
				   success: function (res) {
						wx.saveImageToPhotosAlbum({
							filePath: res.path,
							success() {
							  that.$msg("保存成功");
							},
							fail(e) {
								console.log(e);
							}
						});
				   }
				});
			}
		}
	}
</script>

<style lang="scss">
	.u-page{
		position: absolute;
		left: 0;
		top: 0;
		bottom: 0;
		right: 0;
	}
	.container{
		padding: 0 20rpx;
		background: #eeeeee;
		padding-bottom: 10rpx;
	}
	.item{
		padding: 10rpx;
		background-color: rgba(48, 216, 231, 0.3);
		font-size: 26rpx;	
		margin-bottom: 10rpx;
		.title{
			padding: 10rpx 0;
			font-weight: bold;
			font-size: 30rpx;
		}
		.info{			
			background-color: #fff;
			overflow: hidden;
			.line{
				height: 70rpx;
				line-height: 70rpx;
				padding: 0 20rpx;
				border-bottom: 1px solid #f1f1f1;
				position: relative;
			}
			.line:last-child{
				border-bottom:0;
			}
			.qrcode{
				text-align: center;
				padding: 20rpx;
				image{
					width: 300rpx;
					height: 300rpx;
					margin-bottom: 20rpx;
				}
			}
			.rightbox{
				position: absolute;
				right: 10rpx;
				top:20rpx;
			}
		}
	}
</style>